package com.ravi.core;

import com.ravi.entity.CheckRoom;
import com.ravi.entity.PatientQueueInfo;
import com.ravi.exception.CheckSystemException;
import lombok.Data;

import java.util.concurrent.ConcurrentLinkedDeque;

/**
 *  检查室缓存对象
 *  主要保存 当前叫号人员currentPicker
 *  过号人员 missedCallList
 *
 *  叫号逻辑：
 *  体检者完成检查->队首被叫号->体检者进行体检->体检者完成检查
 *                        |-> 体检者过号-> 队首被叫号
 */
@Data
public class RoomChecking {
	// 表示检查室信息
	private CheckRoom checkRoom;

	// 表示当前叫号者
	private PatientQueueInfo currentPicker;

	// 表示当前诊室过号者
	private ConcurrentLinkedDeque<PatientQueueInfo> missedCallList;

	public RoomChecking(CheckRoom checkRoom) {
		this.checkRoom = checkRoom;
		this.currentPicker = null;
		this.missedCallList = new ConcurrentLinkedDeque<PatientQueueInfo>();
	}

	/**
	 * 设置某个患者被叫号
	 * @param patient
	 */
//	public synchronized CallingMsg callingPatient(PatientQueueInfo patient) {
//		Integer genderRestrictions = checkRoom.getGenderRestrictions();
//		// 性别判断
//		if (genderRestrictions.equals(1)) {
//			if (!patient.getSex().equals("男")) {
//				throw new CheckSystemException( "体检者性别应为男性！");
//			}
//		}else if (genderRestrictions.equals(2)) {
//			if (!patient.getSex().equals("女")) {
//				throw new CheckSystemException( "体检者性别应为女性！");
//			}
//		}
//		this.currentPicker = patient;
//		return new CallingMsg(patient, checkRoom);
//	}

	/**
	 * 设置过号患者，并将当前叫号者设置为null
	 * @param patient
	 */
	public synchronized void setMissCalledPatient(PatientQueueInfo patient) {
		if (this.currentPicker == null) return;
		this.missedCallList.add(this.currentPicker);
		this.currentPicker = null;
	}

	public void setMissCalled(PatientQueueInfo patient) {
		this.missedCallList.add(patient);
	}

}
